package day8;

import java.util.Scanner;

public class Main {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        in.nextLine();
        String[] array = new String[n];
        for (int i = 0; i < n; i++) {
            array[i] = in.nextLine();
        }
        boolean a = true;//按字典顺序排列
        boolean b = true;//按长度排列
        for (int i = 0; i < n-1; i++) {
            boolean c = true;//判断字符串前j可字符是否相等；
            //判断字符串是否按长度排序
            if(array[i].length() > array[i+1].length()) {
                b = false;
            }
            //判断字符串是否按字典序排序
            for (int j = 0; j < (Math.min(array[i].length(),array[i+1].length())); j++) {
                char q = array[i].charAt(j);
                char w = array[i+1].charAt(j);
                if(q > w && c) {
                    a = false;
                }
                //判断要比较的字符串前j个字符是否相同，不相同则没有比较的必要
                if(q != w) {
                    c = false;
                }
            }
            //考虑到字符串字符都是同一个，但是长度不是按顺序排序的情况
            if(!b && c) {
                a = false;
                break;
            }
        }
        if(a && !b) {
            System.out.println("lexicographically");
        }else if (!a && b) {
            System.out.println("lengths");
        }else if(a && b) {
            System.out.println("both");
        }else {
            System.out.println("none");
        }
    }
    public static boolean isDicSort(String[] str) {
        for (int i = 0; i < str.length-1; i++) {
            if(str[i].compareTo(str[i+1]) > 0) {
                return false;
            }
        }
        return true;
    }
    public static boolean isLenSort(String[] str) {
        for (int i = 0; i < str.length-1; i++) {
            if(str[i].length() > str[i+1].length()) {
                return false;
            }
        }
        return true;
    }
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()) {
            int n = in.nextInt();
            String[] str = new String[n];
            for (int i = 0; i < n; i++) {
                str[i] = in.next();
            }
            boolean len = isLenSort(str);
            boolean dic = isDicSort(str);

            if(len && dic) {
                System.out.println("both");
            }else if(len) {
                System.out.println("lengths");
            }else if(dic) {
                System.out.println("lexicographically");
            }else {
                System.out.println("none");
            }
        }
    }
    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            int max = (a > b ? a : b);
            int num = a*b;
            for(;max < num; max++) {
                if(max % a == 0 && max % b == 0) {
                    break;
                }
            }
            System.out.println(max);
        }
    }

    public static void main4(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            int c = a;
            System.out.println(gcb(a,b,c));
        }
    }
    public static int gcb(int a, int b, int c) {
        if(a % b == 0) {
            return a;
        }
        return gcb(a+c, b,c);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
            int c = gdc(a,b);
            System.out.println(a*b/c);
        }
    }
    public static int gdc(int a, int b) {
        if(a == b ) {
            return a;
        }
        int n;
        if(a < b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
        while(a % b > 0) {
            n = a % b;
            a = b;
            b = n;
        }
        return b;
    }
}
